package com.ebpm.designer.pvm
{

	import com.ebpm.designer.NodeContainer;
	import com.ebpm.designer.WF;
	import com.ebpm.designer.mainLayout.variable.Variable;
	
	import flash.events.MouseEvent;
	
	import mx.containers.Canvas;
	
	import spark.components.Group;
	import spark.primitives.BitmapImage;
	
	public class StartEvent extends UserTask
	{
		public function StartEvent(nodeContainer:NodeContainer)
		{
			super(nodeContainer);
			if(this.nodeContainer.variable.desc == null || this.nodeContainer.variable.desc == "") {
				this.nodeContainer.variable.desc = "开始";
			}
		}
		
		override public function initStyle():void 
		{
			this.width = WF.START_EVENT_W;
			this.height = WF.START_EVENT_W;
			this.nodeContainer.width = this.width + WF.ITEM_SIZE * 2;
			this.nodeContainer.height = this.height + WF.ITEM_SIZE * 2;
			initIcon();
		}
		
		override public function initIcon():void {
			var titleIcon:Canvas = new Canvas();
			titleIcon.x = 0;
			titleIcon.y = 0;
			titleIcon.width = this.width;
			titleIcon.height = this.height;
			
			var group:Group = new Group();
			var bi:BitmapImage = new BitmapImage();
			bi.source = WF.Icon_StartEvent;
			bi.x = 0;
			bi.y = 0;
			bi.width = titleIcon.width;
			bi.height = titleIcon.height;
			group.addElement(bi);
			titleIcon.addElement(group);
			this.addElement(titleIcon);
		}
		
//		override public function _mouseOut(event:MouseEvent):void {}
		
		override public function toggleDiaplayDirs():void {}
		
		override public function _mouseUp(event:MouseEvent):void
		{
			//判断是否是item的连线事件			
			drawLineWithItem();
			//判断是否是ctrl的连线事件			
			drawLineWithCtrl();
		}
		
		override public function _mouseOver(event:MouseEvent):void
		{
			WF.wp.hideNodeContainerItems();
			this.nodeContainer.displayItems();
		}
		
		override public function displayVariablePanel():void {
			WF.wp.startEventVariablePanel.showMe();
			WF.wp.startEventVariablePanel.vc.clearContent();
			WF.wp.startEventVariablePanel.vc.initContent(this.nodeContainer.variable);
		}
		
		override public  function buildTaskXml():Boolean {
			var v:Variable = this.nodeContainer.variable;
			WF.xmlDefinitionsData += "\t<StartEvent id=\"" + v.name + "\" name=\"" + v.desc + "\" />\n";
			
			WF.xmlPositionData += "\t<StartEvent id=\"" + v.name + "\"";
			WF.xmlPositionData += " x=\"" + this.nodeContainer.x + "\" y=\"" + this.nodeContainer.y + "\" w=\"" + this.nodeContainer.width + "\" h=\"" + this.nodeContainer.height + "\"";
			var json:String = "{\"type\":\"" + this.className + "\", \"mission\":\"" + v.name + "\",\"x\":" + this.nodeContainer.x + ",\"y\":" + this.nodeContainer.y + ",\"w\":" + this.nodeContainer.width + ",\"h\":" + this.nodeContainer.height + ", \"desc\":\"" + (v.desc==null?"":v.desc) + "\"}";
			WF.xmlTaskJson += json + ",";
			//WF.xmlPositionData += " json=\"" + json + "\"";
			WF.xmlPositionData += " />\n";
			return true;
		}
		
		
		
		
		
		
		
		
		
		
		
		
	}
}